package com.coke.spring.sentinel.controller;

import com.coke.spring.sentinel.common.Product;
import com.coke.spring.sentinel.common.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author cwm
 * @Description TODO
 * @date 2021/8/31 上午11:24
 * @Version 1.0
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @GetMapping("/find/{id}")
    public Result find(@PathVariable("id") String id){
        AtomicReference<Product> product = new AtomicReference<Product>();
        Product.products.stream().forEach(item ->{
            if (item.getId().equals(id)){
                product.set(item);
            }
        });
        return Result.ok(product.get());
    }
}
